package com.google.shop.product.service.impl.product;

import com.google.shop.product.common.utils.R;
import com.google.shop.product.entity.product.ProductSku;
import com.google.shop.product.entity.product.ProductSkuSaleAttrValue;
import com.google.shop.product.entity.product.ProductSpu;
import com.google.shop.product.repository.product.ProductSkuRepository;
import com.google.shop.product.repository.product.ProductSkuSaleAttrValueRepository;
import com.google.shop.product.repository.product.ProductSpuRepository;
import com.google.shop.product.service.member.BuyerAddressService;
import com.google.shop.product.service.product.ProductSkuService;
import com.google.shop.product.vo.product.detailVO.DetailSkuVO;
import com.google.shop.product.vo.product.detailVO.DetailVO;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
/* loaded from: app.jar:BOOT-INF/classes/com/google/shop/product/service/impl/product/ProductSkuImpl.class */
public class ProductSkuImpl implements ProductSkuService {
    @Autowired
    ProductSkuRepository skuRepository;
    @Autowired
    ProductSpuRepository spuRepository;
    @Autowired
    ProductSkuSaleAttrValueRepository skuSaleAttrValueRepository;
    @Autowired
    BuyerAddressService buyerAddressService;

    @Override // com.google.shop.product.service.product.ProductSkuService
    public DetailVO findDetailByskuId(Integer skuId, Integer skuNum, Integer addressId) {
        DetailVO detailVO = new DetailVO();
        DetailSkuVO detailSkuVO = new DetailSkuVO();
        ProductSku productSku = this.skuRepository.findBySkuId(skuId);
        ProductSpu productSpu = this.spuRepository.findBySpuId(productSku.getSpuId());
        detailSkuVO.setSpuName(productSpu.getSpuTitle());
        detailSkuVO.setFreight(productSpu.getFreight());
        detailSkuVO.setBuyNum(skuNum);
        detailSkuVO.setSkuPrice((Double.valueOf((double) productSku.getSkuPrice().intValue()).doubleValue() / 100.0d) + "");
        if (productSku.getS1() == null || productSku.getS1() == "") {
            detailSkuVO.setSpuHomeImageOrSkuS1Image(productSpu.getSpuHomeImage());
        } else {
            detailSkuVO.setSpuHomeImageOrSkuS1Image(this.skuSaleAttrValueRepository.findBySaleAttrValueId(Integer.valueOf(productSku.getS1())).getSkuFirstLineSaleAttrValueImage());
        }
        detailSkuVO.setAmount(BigDecimal.valueOf(((Double.valueOf(productSku.getSkuPrice() + "").doubleValue() / 100.0d) * ((double) skuNum.intValue())) + ((double) productSpu.getFreight().intValue())));
//        detailSkuVO.setSkuTag((String[]) Arrays.stream(((List) this.skuSaleAttrValueRepository.findBySpuId(productSku.getSpuId()).stream().filter(s -> {
//            return new StringBuilder().append(s.getSaleAttrValueId()).append("").toString().equals(productSku.getS1()) || new StringBuilder().append(s.getSaleAttrValueId()).append("").toString().equals(productSku.getS2()) || new StringBuilder().append(s.getSaleAttrValueId()).append("").toString().equals(productSku.getS3()) || new StringBuilder().append(s.getSaleAttrValueId()).append("").toString().equals(productSku.getS4()) || new StringBuilder().append(s.getSaleAttrValueId()).append("").toString().equals(productSku.getS5()) || new StringBuilder().append(s.getSaleAttrValueId()).append("").toString().equals(productSku.getS6());
//        }).collect(Collectors.toList())).stream().map(s -> {
//            return s.getSkuSaleAttrValue();
//        }).toArray()).toArray(x$0 -> {
//            return new String[x$0];
//        }));
        //获取sku销售属性值
        List<ProductSkuSaleAttrValue> skuSaleAttrValueList = skuSaleAttrValueRepository.findBySpuId(productSku.getSpuId());
        List<ProductSkuSaleAttrValue> productSkuSaleAttrValueList = skuSaleAttrValueList.stream()
                .filter(s -> (s.getSaleAttrValueId() + "").equals(productSku.getS1())
                        || (s.getSaleAttrValueId() + "").equals(productSku.getS2())
                        || (s.getSaleAttrValueId() + "").equals(productSku.getS3())
                        || (s.getSaleAttrValueId() + "").equals(productSku.getS4())
                        || (s.getSaleAttrValueId() + "").equals(productSku.getS5())
                        || (s.getSaleAttrValueId() + "").equals(productSku.getS6())
                ).collect(Collectors.toList());
        Object[] objectArray = productSkuSaleAttrValueList.stream().map(s -> s.getSkuSaleAttrValue()).toArray();
        String[] stringArray = Arrays.stream(objectArray).toArray(String[]::new);
        detailSkuVO.setSkuTag(stringArray);

        List<DetailSkuVO> detailSkuVOList = new ArrayList<>();
        detailSkuVOList.add(detailSkuVO);
        detailVO.setDetailSkuVOList(detailSkuVOList);
        if (addressId != null) {
            detailVO.setBuyerAddress(R.ok(this.buyerAddressService.findLineById(addressId)).getData());
        }
        return detailVO;
    }
}
